/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution
{
public:
    int sumOfLeftLeaves(TreeNode *root)
    {
        return sumOfLeftLeaves(root, false);
    }

    int sumOfLeftLeaves(TreeNode *tree, bool isLeftChild)
    {
        if (tree == nullptr)
        {
            return 0;
        }
        if (isLeftChild && tree->left == nullptr && tree->right == nullptr)
        {
            return tree->val;
        }
        int result = 0;
        result += sumOfLeftLeaves(tree->left, true);
        result += sumOfLeftLeaves(tree->right, false);
        return result;
    }
};